#pragma warning(disable:4996)
#pragma warning(disable:6031)

#include <stdio.h>
#include <stdlib.h>

typedef struct list
{
	int n;
	struct list* next;
}list;

list* buy(int n)
{
	list* newnode = (list*)malloc(sizeof(list));
	if (newnode == NULL)
	{
		exit(-1);
	}
	newnode->n = n;
	newnode->next = NULL;
	return newnode;
}

void push(list** pphead, int n)
{
	list* newnode = buy(n);
	if (*pphead == NULL)
	{
		*pphead = newnode;
	}
	else
	{
		list* p = *pphead;
		while (p->next != NULL)
		{
			p = p->next;
		}
		p->next = newnode;
	}
}

void insert(list** pphead, int i, int n)
{
	list* newnode = buy(n);
	if (*pphead == NULL || i == 0)
	{
		*pphead = newnode;
	}
	else
	{
		list* p = *pphead;
		while (--i)
		{
			p = p->next;
		}
		newnode->next = p->next;
		p->next = newnode;
	}
}

void print(list* phead)
{
	list* p = phead;
	while (p != NULL)
	{
		printf("%d ", p->n);
		p = p->next;
	}
}

int main()
{
	int n = 0;
	int m = 0;
	int i = 0;
	int j = 0;
	int num = 0;
	list* p = NULL;
	scanf("%d%d", &n, &i);
	num = i;
	if (i > n)
	{
		i = n;
	}
	for (j = 0; j < n; j++)
	{
		scanf("%d", &m);
		push(&p, m);
	}
	insert(&p, i, num);
	print(p);
	return 0;
}